package hutool;

import cn.hutool.core.io.FileUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: DRevelation
 * @Date: 2021/2/20 14:11
 */
public class FileUtilDemo {
    public static void main(String[] args) {
        String xmlContent = FileUtil.readString("D:\\60318bd650524f77b60258a270f1a81aREGIST.xml", "utf-8");
        System.out.println("xmlContent = " + xmlContent);
        Map<String, String> map = getFtpInfo("ftp://atv:rYH549fPQuDI!@ftp.h3c.ahntv.cn/3e8c495e5d9d4b4ab4b1e74a5c172f01.mp4");
        for (Map.Entry<String, String> entry : map.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }
    }

    private static Map<String, String> getFtpInfo(String CmdFileURL) {
        Map<String, String> map = new HashMap<>();
        String pathAndFileName = "";
        final String ftpFlag = "ftp://";
        final String cutedFtp = CmdFileURL.substring(CmdFileURL.indexOf(ftpFlag) + ftpFlag.length());

        // 首先截取ip和端口
        String prefix = "";
        prefix = cutedFtp.substring(0, cutedFtp.indexOf("/"));
        pathAndFileName = cutedFtp.substring(cutedFtp.indexOf("/"));

        String[] str = prefix.split("@");
        String userNameAndPwd = str[0];
        String urlAndPort = str[1];

        String[] userNameAndPwdArray = userNameAndPwd.split(":");
        String[] urlAndPortArray = urlAndPort.split(":");

        String userName = userNameAndPwdArray[0];
        String pwd = userNameAndPwdArray[1];

        String ip = "127.0.0.1";
        String port = "21";
        if (urlAndPortArray.length > 1) {
            ip = urlAndPortArray[0];
            port = urlAndPortArray[1];
        } else {
            ip = urlAndPortArray[0];
        }

        map.put("pathAndFileName", pathAndFileName);
        map.put("ip", ip);
        map.put("port", port);
        map.put("userName", userName);
        map.put("pwd", pwd);
        return map;
    }
}
